/**
 * Copyright (c) 2021 Choice, Inc.
 * All Rights Reserved.
 * Choice Proprietary and Confidential.
 */
package cn.ruleengine.web.vo.monitor;

import java.io.Serializable;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

import lombok.Data;
import lombok.Getter;
import lombok.ToString;

@Data
public class ConsensusResponse implements Serializable {
    private static final long serialVersionUID = -5323323040177154628L;

    private final String  shareCode;

    private Integer result;
    private String  massage;
    private String  reason;

    public static ConsensusResponse of(String shareCode, Status status, String reason) {
        ConsensusResponse response = new ConsensusResponse(shareCode);
        if (status == null) {
            status = Status.agree;
        }
        response.setResult(status.getK());
        response.setMassage(status.getV());
        response.setReason(reason);
        return response;
    }

    @Getter
    @ToString
    public enum Status {
        absolute(1, "强制互认"),
        refuse(2, "不可互认"),
        agree(3, "可互认"),
        ;
        private Integer k;
        private String  v;

        Status(Integer k, String v) {
            this.k = k;
            this.v = v;
        }

        static Map<String, Status> map = new HashMap<>();

        static {
            for (Status item : EnumSet.allOf(Status.class)) {
                map.put(item.getV(), item);
            }
        }

        public static Status of(String v) {
            return map.get(v);
        }
    }
}
